<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="format-detection" content="telephone=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <link href="css/SYSFrame.css" rel="stylesheet" type="text/css" />
    <link href="font/iconfont.css" rel="stylesheet" type="text/css" />
    <link href="css/module.css" rel="stylesheet" type="text/css" />
    <link href="css/pages.css" rel="stylesheet" type="text/css" />
    <title>商品管理</title>
    <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.nicescroll.js" type="text/javascript"></script>
    <script src="js/HUpages.js" type="text/javascript"></script>

    <script src="js/template.js" type="text/javascript"></script>
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js" type="text/javascript"></script>
    <script src="js/css3-mediaqueries.js"  type="text/javascript"></script>
    <![endif]-->
</head>

<body id="situation" class="pagebox">
<div class="pages-style">
    <!--右侧内容-->
    <div class="bk-con-message message-section" id="iframe_box">
        <!--编辑内容-->
        <div class="operation  mb15 relative">
            <button class="btn button_btn btn-danger" type="button" onclick=""><i class="iconfont"></i>&nbsp;批量删除</button>
            <button name="edit_product.html?productid=0" class="btn button_btn bg-deep-blue menuUl_title" type="button" data-id="278" title="添加商品"><i class="iconfont"></i>&nbsp;添加商品</button>
            <button class="btn button_btn bg-deep-gray" type="button" onclick=""><i class="iconfont"></i>&nbsp;添加分类</button>
            <span class="sumQuantity">合计数量：<em id="quantity"></em>件</span>
        </div>
        <!--列表内容-->
        <div class="page_content clearfix mb15 table-module ">
            <table class="gallery table table_list table_striped table-bordered " id="tableList">
                <thead>
                <tr>
                    <th width="50px"><label class="checkbox relative"><input type="checkbox" class="ace" name="checkbox"><span class="lbl"></span></label></th>
                    <th>分类</th>
                    <th width="70">图片</th>
                    <th width="350">产品名称</th>
                    <th width="100">原价/元</th>
                    <th width="100">商城价/元</th>
                    <th>产地</th>
                    <th width="100">数量</th>
                    <th>状态</th>
                    <th>加入时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="productlist">
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>

</html>
<script id="sorthtml" type="text/html">
    <li class="sortstyle relative" data-id="0" ischek="true">
        <a href="javascript:void(0)" class="block sortname clickBombbox selected">
            全部
        </a>
    </li>
    <% for(var i = 0; i < sorts.length; i++) { %>
    <li class="sortstyle relative" data-id="<%=sorts[i].id%>" ischek="false">
        <a href="javascript:void(0)" class="block sortname clickBombbox">
            <%=sorts[i].name%> (
            <%=sorts[i].quantity %> )
            <% if(sorts[i].classify!=""){%>
            <i class="iconfont arrow">&#xe615</i>
            <% } %>
        </a>
        <% if(sorts[i].classify!=""){%>
        <ul class="grades-list Bombbox">
            <% for(var j = 0; j < sorts[i].classify.length; j++) { %>
            <li>
                <a href="javascript:void()" class="block">
                    <%=sorts[i].classify[j].name%> (
                    <%=sorts[i].classify[j].quantity %> )</a>
            </li>
            <% } %>
        </ul>
        <% }%>
    </li>
    <% } %>
</script>
<!--列表编辑-->
<script id="producthtml" type="text/html">
    <% for(var i = 0; i < list.length; i++) { %>
    <tr class="relative">
        <td><label class="checkbox relative"><input type="checkbox" class="ace" name="checkbox"><span class="lbl"></span></label></td>
        <td>
            <% for(var s = 0; s < sorts.length; s++) { %>
            <% if(sorts[s].id==list[i].sort) {%>
            <%=sorts[s].name%>
            <%}%>
            <% } %>

        </td>
        <td><img src="images/product_img/<%=list[i].defaultimg%>" width="60px" height="60px" /></td>
        <td>
            <%=list[i].name%>
        </td>
        <td>
            <%=list[i].yprice%>
        </td>
        <td>
            <%=list[i].xprice%>
        </td>
        <td>
            <%=list[i].origin%>
        </td>
        <td class="quantity">
            <%=list[i].quantity%>
        </td>
        <td>
            <% if(list[i].status==0) {%>
            <span class="name_status  plf10 btn btn-gray" data-id="0">下架</span>
            <%} if(list[i].status==1) {%>
            <span class="name_status  plf10 btn btn-green" data-id="1">上架</span>
            <%}%>
        </td>
        <td>
            <%=timestamp(list[i].time,'yyyy-MM-dd hh:mm')%>
        </td>
        <td>
            <button class="btn btn-danger padding5" onclick="">删除</button>
            <button class="btn btn-blue padding5 menuUl_title" type="button" name="edit_product.html?productid=<%=list[i].id%>" data-id="279" title="编辑修改">编辑</button>
        </td>
    </tr>
    <% } %>
</script>
<script>
    $(function() {
        //内页框架结构编辑
        $("#situation").Hupage({
            slide: '#breadcrumb',
            padding: 15,
            menuModule: '#bk-con-menu', //菜单模块
            pagecontent: '.page_content', //自定义属性
            operation: '.operation', //自定义属性
            scrollbar: function(e) {
                e.niceScroll({
                    cursorcolor: "#dddddd",
                    cursoropacitymax: 1,
                    touchbehavior: false,
                    cursorwidth: "3px",
                    cursorborder: "0",
                    cursorborderradius: "3px",
                });
            },
            expand: function(thisBox, settings) {
                var pc = "";
                $(settings.pagecontent).css("margin-bottom") != null ? pc = parseInt($(settings.pagecontent).css("margin-bottom").replace("px", "")) : '';
                $(settings.pagecontent).css({
                    height: $(window).height() - $(settings.operation).outerHeight() - pc - (settings.padding * 2)
                })
                settings.scrollbar($(settings.slide) && $(settings.pagecontent));
                //获取设置url
                $.getUrlParam = function(name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                    var r = window.location.search.substr(1).match(reg);
                    if(r != null) return unescape(r[2]);
                    return null;
                }
                var id = $.getUrlParam('id'); //获取其中的参数值
                //编辑数据
                var lavem = 500; //设置产品少于多少是提示补货信息
                var advertisMore = function(callback) {
                    $.ajax({
                        url: "json/products.json",
                        type: "GET",
                        dataType: 'json',
                        success: function(ret) {
                            typeof callback == 'function' && callback(ret);
                        },
                    });
                };
                advertisMore(function(listArr) {
                    var listhtml = $('#productlist');
                    var sorthtml = $("#productSort");
                    var html = template('producthtml', {
                        id: id,
                        list: listArr.data,
                        sorts: listArr.sort
                    });
                    var s = listArr.data.length;
                    $("#quantity").html(s);
                    var shtml = template('sorthtml', {
                        sorts: listArr.sort
                    });
                    listhtml.append(html);
                    sorthtml.append(shtml);
                    var datas = listArr.data;
                    for(var i = 0; i < datas.length; i++) {
                        var surplus = datas[i].quantity - datas[i].sales;
                        if(surplus < lavem) {
                            listhtml.find('tr .quantity').eq(i).html('请及时补充货源').addClass('pro-prompt');
                        }
                    }
                    new TableSorter("tableList", 4, 5, 7, 9); //设置
                    $("#situation").Hupage({});//加载完数据执行
                });
            } //自定义方法
        });
    })
</script>
<script src="js/common.js" type="text/javascript"></script>